#!/usr/bin/python

# hello-server.py

import socket
import time

serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('', 8888))
serversocket.listen(5)

while True:
    (clientsocket, address) = serversocket.accept()  # 等待客户端连接
    data = clientsocket.recv(4096).decode()          # 接收姓名并解码
    datetime = time.asctime()
    response = f'Hello {data}\nMy time is {datetime}\n'
    clientsocket.send(response.encode())             # 发送回复
    clientsocket.close()                             # 关闭连接